﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="TotalCompras.aspx.cs" Inherits="Purchases_TotalCompras" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <script>
        $(function () {
            $("#dateInit").datepicker({ dateFormat: 'yy-mm-dd' });
            $("#dateEnd").datepicker({ dateFormat: 'yy-mm-dd' });

            $("#search").click(function () {
                $("#spinner").show();
                var dateInit = Date.parse($("#dateInit").val());
                var dateEnd = Date.parse($("#dateEnd").val());
                if (dateInit < dateEnd) {
                    $.ajax({
                        type: 'POST',
                        url: 'http://localhost:1661/Web/Webservices/TotalComprasWS.asmx/getTotalCompras',
                        data: {
                            dateInit: $("#dateInit").val(),
                            dateEnd: $("#dateEnd").val(),
                            branchId: $("#MainContent_ddlBranches").val()
                        },
                        dataType: 'xml',
                        success: function (xml) {
                            $("#result").empty();
                            var data;
                            $(xml).find('string').each(function () {
                                data = eval("(" + $(this).text() + ')');
                            });
                            var length = data.length;
                            if (length > 0) {
                                $("#result").append('<table style="color:#333333;width:223px;border-collapse:collapse;margin-right: 3px"><thead><tr style="color:White;background-color:#507CD1;font-weight:bold;"><td align="center">Sucursal</td><td align="center">Cantidad de compras</td></tr></thead><tbody></tbody></table>');
                                $("#result").find("table").find("tbody").empty();
                                for (var i = 0; i < length; i++) {
                                    var style = i % 2 == 0 ? "background-color:#EFF3FB;" : "background-color:white;";
                                    $("#result").find("table").find("tbody").append("<tr style='" + style + "'><td align='center'>" + data[i].BranchName + "</td><td align='center'>" + data[i].Purchases + "</td></tr>");
                                }
                            } else {
                                $("#result").append("<p>No hay resultados.</p>");
                            }
                            $("#spinner").hide();
                        }
                    });
                } else {
                    alert("Las fecha de inicio debe ser mayor a la de fin.");
                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <h2>
        Totalidad de compras
    </h2>
    <div style="height: 25px; width: 100%; padding-top: 10px">
        <div style="float: left">
            Fecha inicio:&nbsp;<input id="dateInit" type="text" name="dateInit" size="10" />&nbsp;&nbsp;
            Fecha fin:&nbsp;<input id="dateEnd" type="text" name="dateEnd" size="10" />&nbsp;&nbsp;
            Sucursal:&nbsp;<asp:DropDownList ID="ddlBranches" runat="server" DataTextField="BranchName"
                DataValueField="BranchId" AppendDataBoundItems="true">
                <asp:ListItem Text="Todas" Value="null"></asp:ListItem>
            </asp:DropDownList>
            <div style="display: inline; padding-top: 3px">
                <img src="../Images/icon_ok.png" border="0" id="search" alt="Buscar" /></div>
        </div>
        <div id="spinner" style="float: right; display: none">
            <img src="../Images/spinner.gif" border="0" alt="Loading" /></div>
    </div>
    <div id="result" style="height: auto; padding-top: 10px">
    </div>
    <asp:HyperLink ID="Hyperlink1" runat="server" NavigateUrl="~/Purchases/GMaps.aspx">Mapa</asp:HyperLink>

</asp:Content>
